package com.dk.service.impl;

import com.dk.mapper.WmMaterialStockMapper;
import com.dk.pojo.CodeRule;
import com.dk.pojo.WmMaterialStock;
import com.dk.pojo.WmMaterialStockExample;
import com.dk.result.PageResult;
import com.dk.service.StockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LTZ
 * @create 2023/5/11
 */
@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private WmMaterialStockMapper stockMapper;

    @Override
    public PageResult<WmMaterialStock> getStockInfo(Integer pageNum, Integer pageSize, String itemCode, String itemName, String warehouseName, String vendorName) {
//        WmMaterialStockExample example = new WmMaterialStockExample();
//        if(itemName != null && itemName.length() > 0){
//            example.createCriteria().andItemNameLike("%"+itemName+"%");
//        }
//        if(itemCode != null && itemCode.length() > 0){
//            example.createCriteria().andItemCodeEqualTo(itemCode);
//        }
//        if(warehouseName != null && warehouseName.length() > 0){
//            example.createCriteria().andWarehouseNameLike("%"+warehouseName+"%");
//        }
//        if(vendorName != null && vendorName.length() > 0){
//            example.createCriteria().andVendorNameLike("%"+vendorName+"%");
//        }
        PageHelper.startPage(pageNum, pageSize);
        List<WmMaterialStock> stockList = stockMapper.getStockInfo(itemCode,itemName,warehouseName,vendorName);
        PageInfo<WmMaterialStock> pb = new PageInfo<>(stockList);
        PageResult<WmMaterialStock> result = new PageResult<>(pb.getPageNum(), pb.getPageSize(), pb.getTotal(),pb.getList());
        return result;
    }

    @Override
    public void addStock(WmMaterialStock stock) {
        stockMapper.insertSelective(stock);
    }
}